ActiveAdmin.register CoachOrder do
  menu label: '培训', parent: '订单'

  actions :index
  filter :phone, as: :string, label: '手机号'
  filter :appointment_training_name, as: :string, label: '培训名'
  filter :order_no
  filter :total
  filter :created_at

  csv do
    column :order_no
    column '教练' do |o|
      o.name
    end
    column '手机号' do |o|
      o.mobile
    end
    column '产品' do |o|
      o.product
    end
    column '订单金额' do |o|
      o.total
    end
    column '优惠金额' do |o|
      o.coupon
    end
    column '支付金额' do |o|
      o.pay_amount
    end
    column '下单时间' do |o|
      o.created_at
    end
    column :status do |o|
      o.status_i18n
    end
  end

  controller do
    def scoped_collection
      CoachOrder.joins(:member, :appointment).select(
          :id,
          :order_no,
          'members.name as name',
          'members.mobile as mobile',
          'training_appointments.training_name as product',
          'coach_orders.amount as total',
          '0 as coupon',
          'actually as pay_amount',
          :status,
          :created_at
      )
    end
  end

  index do
    column :order_no
    column '用戶', :name
    column '联系电话', :mobile
    column '购买产品', :product
    column '订单金额', :total
    column '优惠金额', :coupon
    column '支付金额', :pay_amount
    column '下单时间', :created_at
    column :status do |o|
      o.status_i18n
    end
  end
end
